<!DOCTYPE html>
<html>
<head>
<title>Density of States Diagram</title>
<style>
  body {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    margin: 0;
  }
  canvas {
    border: 1px solid #ccc;
  }
</style>
</head>
<body>
<canvas id="physicsCanvas" width="550" height="450"></canvas>
<script>
  const canvas = document.getElementById('physicsCanvas');
  const ctx = canvas.getContext('2d');

  // Style settings
  ctx.strokeStyle = 'black';
  ctx.fillStyle = 'black';
  ctx.lineWidth = 2;
  ctx.font = 'italic 20px "Times New Roman"';
  ctx.textAlign = 'center';

  // --- Define Coordinate System Parameters ---
  const originX = 100;
  const originY = 380;
  const axisLengthX = 400;
  const axisLengthY = 280;
  const arrowSize = 8;

  // --- Draw Axes ---
  // X-axis (Energy E)
  ctx.beginPath();
  ctx.moveTo(originX, originY);
  ctx.lineTo(originX + axisLengthX, originY);
  // Arrow for X-axis
  ctx.lineTo(originX + axisLengthX - arrowSize, originY - arrowSize);
  ctx.moveTo(originX + axisLengthX, originY);
  ctx.lineTo(originX + axisLengthX - arrowSize, originY + arrowSize);
  ctx.stroke();

  // Y-axis (Density of States D(E))
  ctx.beginPath();
  ctx.moveTo(originX, originY);
  ctx.lineTo(originX, originY - axisLengthY);
  // Arrow for Y-axis
  ctx.lineTo(originX - arrowSize, originY - axisLengthY + arrowSize);
  ctx.moveTo(originX, originY - axisLengthY);
  ctx.lineTo(originX + arrowSize, originY - axisLengthY + arrowSize);
  ctx.stroke();

  // --- Draw Labels for Axes ---
  // 'E' label for x-axis
  ctx.fillText('E', originX + axisLengthX + 15, originY + 8);
  // 'D(E)' label for y-axis
  ctx.textAlign = 'left';
  ctx.fillText('D(E)', originX + 15, originY - axisLengthY + 5);

  // --- Draw the Density of States Curve ---
  // The curve D(E) vs E, which looks like sqrt(E).
  // We use a cubic Bezier curve to get the desired shape.
  // P0: Start point (origin)
  const p0 = { x: originX, y: originY };
  // P3: End point of the curve
  const p3 = { x: originX + 380, y: originY - 200 };
  // P1: Control point 1, to make the initial slope steep
  const p1 = { x: originX + 10, y: originY - 90 };
  // P2: Control point 2, to control the final slope
  const p2 = { x: originX + 300, y: originY - 180 };
  
  ctx.beginPath();
  ctx.moveTo(p0.x, p0.y);
  ctx.bezierCurveTo(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y);
  ctx.stroke();

  // --- Mark the Fermi Energy (E_F) ---
  const ef_x = originX + 260;
  // Approximate y on the curve for a given x without solving the cubic equation.
  // By visual inspection of the Bezier curve, this is a reasonable approximation.
  const t_approx = 0.7; // Approximate parameter t for the bezier curve
  const ef_y = Math.pow(1 - t_approx, 3) * p0.y + 3 * Math.pow(1 - t_approx, 2) * t_approx * p1.y + 3 * (1 - t_approx) * Math.pow(t_approx, 2) * p2.y + Math.pow(t_approx, 3) * p3.y;

  // Vertical line from E_F on the axis to the curve
  ctx.beginPath();
  ctx.moveTo(ef_x, originY);
  ctx.lineTo(ef_x, ef_y);
  ctx.stroke();
  
  // Label for E_F
  ctx.textAlign = 'center';
  ctx.font = 'italic 20px "Times New Roman"';
  ctx.fillText('E', ef_x, originY + 25);
  // Draw the subscript 'F'
  ctx.font = 'italic 14px "Times New Roman"';
  ctx.fillText('F', ef_x + 9, originY + 28);
  
  // --- Draw the Figure Caption ---
  ctx.font = '16px "Times New Roman"';
  ctx.fillText('Fig. 2.20.', canvas.width / 2, canvas.height - 20);

</script>
</body>
</html>